package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin;

import java.util.Date;

import com.gwtext.client.widgets.HTMLPanel;

/**
 * @author Renato Miceli
 */
public class MainBottomPanel extends HTMLPanel implements Logger {

	private final StringBuffer buf;

	public MainBottomPanel() {

		this.buf = new StringBuffer();

		this.setHeight(100);
		this.setCollapsible(true);
		this.setTitle("Tracking Monitor");
		this.setAutoScroll(true);

		this.log("Admin logged in.");
	}

	/**
	 * {@inheritDoc}
	 */
	public void log(String message) {
		this.buf.insert(0, "<b><font size=1><p>[" + new Date() + "] " + message + "</p></font></b>");
		this.setHtml(buf.toString());
	}

	/**
	 * {@inheritDoc}
	 */
	public void logError(String message, Throwable error) {
		this.buf.insert(0, "<b><font color=\"red\" size=1><p>[" + new Date() + "] " + message + ": " + error.getMessage() + "</p></font></b>");
		this.setHtml(buf.toString());
	}

}
